public class p1018_313ms_28th {

	static//
	// -----
	// -----
	public class Main {
		public static void main(String[] args) throws Exception {
			java.util.Scanner in = new java.util.Scanner(System.in);
			int n = in.nextInt();
			for (int i = 0; i < n; i++)
				process(in);
		}

		static void process(java.util.Scanner in) {
			// list of [bandwidth, price]
			java.util.List<int[]> solutions = new java.util.ArrayList<int[]>();
			solutions.add(new int[] { Integer.MAX_VALUE, 0 });

			int n = in.nextInt();
			for (int i = 0; i < n; i++)
				solutions = mergeSolution(solutions, readDevices(in));

			double maxRatio = -1;
			for (int[] solution : solutions)
				maxRatio = Math.max(maxRatio, ((double) solution[0]) / solution[1]);
			System.out.printf("%.3f\n", maxRatio);
		}

		static java.util.List<int[]> readDevices(java.util.Scanner in) {
			java.util.List<int[]> devices = new java.util.ArrayList<int[]>();

			int n = in.nextInt();
			for (int i = 0; i < n; i++) {
				int bandwidth = in.nextInt();
				int price = in.nextInt();
				devices.add(new int[] { bandwidth, price });
			}
			java.util.Collections.sort(devices, new java.util.Comparator<int[]>() {
				public int compare(int[] o1, int[] o2) {
					int price = o1[1] - o2[1];
					return price == 0 ? o2[0] - o1[0] : price;
				}
			});

			int lastBandwidth = -1;
			java.util.Iterator<int[]> iterator = devices.iterator();
			while (iterator.hasNext()) {
				int bandwidth = iterator.next()[0];
				if (bandwidth > lastBandwidth)
					lastBandwidth = bandwidth;
				else
					iterator.remove();
			}
			return devices;
		}

		static java.util.List<int[]> mergeSolution(java.util.List<int[]> solution, java.util.List<int[]> devices) {
			java.util.List<int[]> next = new java.util.ArrayList<int[]>();
			int si = 0, di = 0;
			while (si < solution.size() && di < devices.size()) {
				int sbandwidth = solution.get(si)[0], dbandwidth = devices.get(di)[0];
				int sprice = solution.get(si)[1], dprice = devices.get(di)[1];

				int bandwidth = Math.min(sbandwidth, dbandwidth);
				int price = sprice + dprice;
				next.add(new int[] { bandwidth, price });

				if (bandwidth == sbandwidth)
					si++;
				if (bandwidth == dbandwidth)
					di++;
			}
			return next;
		}

	}

	// -----
	// -----

	public static void main(String[] args) throws Exception {
		Judge.run();
	}

}
